#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_exam1.py
# author:王雯雯
# datetime:2024-11-12 
# software: PyCharm

import random
from collections import Counter

def generate_ip_file():
    with open("ip.txt", "w") as f:
        for _ in range(1200):
            ip_parts = [172, 25, 254, random.randint(1, 254)]
            ip = ".".join(map(str, ip_parts))
            f.write(ip + "\n")


def count_top_10_ips():
    ip_counts = Counter()
    with open("ip.txt", "r") as f:
        for line in f.readlines():
            ip = line.strip()
            ip_counts[ip] += 1

    return ip_counts.most_common(10)

generate_ip_file()
print(count_top_10_ips())